﻿using System;
using System.Data.Common;
using System.Data.OracleClient;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
using Npgsql;

namespace LiJ.Orm.Extention
{
    public static class DbProviderFactories
    {
        public static DbProviderFactory GetFactory(string providerName)
        {
            if (string.IsNullOrEmpty(providerName)) throw new Exception("数据库连接字符串配置不正确！");

            if (providerName.ToLower().Contains("mysql"))
            {
                return MySqlClientFactory.Instance;
            } else if (providerName.ToLower().Contains("sqlserver"))
            {
                return SqlClientFactory.Instance;
            } else if (providerName.ToLower().Contains("oracle"))
            {
                return OracleClientFactory.Instance;
            } else if (providerName.ToLower().Contains("postgresql"))
            {
                return NpgsqlFactory.Instance;
            }

            throw new Exception("暂不支持您使用的数据库类型！");
        }
    }
}